package javase.lambda;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 练习 lambda 表达式用法
 */
class Arrays_ComparatorDemo {
    public static void main(String[] args) {
        Student s1 = new Student("张三",17,178.5);
        Student s2 = new Student("李四",29,188.5);
        Student s3 = new Student("王五",27,198.5);
        Student[] students = {s1,s2,s3};
        //1.调用Arrays.sort方法 (引用数据类型数组 , new Comparator)
        Arrays.sort(students, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return Double.compare(o2.getStuHeight(),o1.getStuHeight());
            }
        });

        //2.简化
//        Arrays.sort(students, (Student o1, Student o2) ->{return Double.compare(o2.getStuHeight(),o1.getStuHeight());});
//        System.out.println(Arrays.toString(students));

        //3.简化
        Arrays.sort(students, (o1, o2) ->{return Double.compare(o2.getStuHeight(),o1.getStuHeight());});

        System.out.println(Arrays.toString(students));
    }
}
